<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>重点关注-关注查补</title>
    <link rel="stylesheet" href="/layui/v10/layui.css" media="all">
</head>
<body>
<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-header"></div>
                <div class="layui-card-body">
                    <!-- 查询条件 -->
                    <form id="searchForm" class="layui-form-item">
                        <div class="layui-input-inline">
                            <label for="nsrsbh"></label>
                            <input type="text" id="nsrsbh" class="layui-input"
                                   autocomplete="off"
                                   placeholder="请输入纳税人识别号">
                        </div>
                        <div class="layui-input-inline">
                            <label for="nsrmc"></label>
                            <input type="text" id="nsrmc" class="layui-input"
                                   autocomplete="off"
                                   placeholder="请输入企业名称">
                        </div>
                        <div class="layui-input-inline">
                            <label for="yzrqTime"></label>
                            <input type="text" readonly class="layui-input" id="yzrqTime"
                                   placeholder="请选择应征日期">
                        </div>
                        <div class="layui-input-inline layui-form">
                            <label for="caseType"></label>
                            <select id="caseType">
                                <option value="" selected disabled>请选择案件类型</option>
                                <option value="1">稽查</option>
                                <option value="2">自查</option>
                            </select>
                        </div>
                        <div class="layui-input-inline layui-form">
                            <label for="checkKeShi"></label>
                            <select id="checkKeShi"></select>
                        </div>
                        <div class="layui-input-inline layui-form">
                            <label for="area"></label><select id="area">
                        </select>
                        </div>
                        <div class="layui-input-inline" style="width: auto">
                            <button type="button" class="layui-btn" lay-submit="" lay-filter="search">查询
                            </button>
                            <button type="button" class="layui-btn" lay-submit="" lay-filter="reset">重置
                            </button>
                            <button type="button" class="layui-btn" lay-submit="" lay-filter="export">导出</button>
                        </div>
                    </form>
                    <!-- 表格 -->
                    <div style="margin-top: 10px">
                        <table class="layui-hide" id="income_table" lay-filter="income_table"></table>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<script src="/layui/v10/layui.js"></script>
<script src="/js/core.util.js"></script>
<script th:inline="none">
    //获取token
    var token = CoreUtil.getData("access_token");
    //地址栏转义token中的#号
    var tokenQuery = token.replace("#", "%23");
    var tableIns1;
    var table = layui.table;
    var form = layui.form;
    var layer = layui.layer;
    var $ = jQuery = layui.jquery;
    var laydate = layui.laydate;
    var tree = layui.tree;
    var startTime = null;
    var endTime = null;
    layui.config({
        base: '/'
    }).extend({
        eleTree: 'layui-ext/eleTree/eleTree'
    }).use(['table', 'laypage', 'layer', 'laydate', 'tree', 'eleTree'], function () {
        // 表格
        tableIns1 = table.render({
            elem: '#income_table'
            , contentType: 'application/json'
            , headers: {"authorization": token}
            , title: "关注查补"
            , page: true
            , url: '/gzcb/queryGzcbData' //数据接口
            , method: 'POST'
            , totalRow: true   //开启表格的合计行
            , parseData: function (res) { //将原始数据解析成 table 组件所规定的数据
                return {
                    "code": res.code, //解析接口状态
                    "msg": res.msg, //解析提示文本
                    "count": CoreUtil.isEmpty(res.data) ? 0 : res.data.total, //解析数据长度
                    "data": CoreUtil.isEmpty(res.data) ? null : res.data.records //解析数据列表
                }
            }
            , cols: [
                [
                    // {type: 'checkbox', fixed: 'left'},
                    {
                        field: 'ajbh',
                        title: '案件编号',
                        width: 200,
                        align: 'center',
                        totalRowText: "汇总",
                        templet: function (d) {
                            return d.ajbh + "\t";
                        }, sort: true
                    },
                    {field: 'nsrsbh', title: '纳税人识别号', width: 200, align: 'center', sort: true},
                    {field: 'nsrmc', title: '纳税人名称', width: 240, align: 'center', sort: true},
                    {field: 'jcks', title: '检查科室', width: 240, align: 'center', sort: true},
                    {field: 'jcr', title: '检查人', width: 280, align: 'center', sort: true},
                    {field: 'area', title: '所属区', width: 200, align: 'center', sort: true},
                    {field: 'zsxm', title: '征收项目', width: 180, align: 'center', sort: true},
                    {field: 'zspm', title: '征收品目', width: 180, align: 'center', sort: true},
                    {field: 'sksx', title: '税款属性', width: 180, align: 'center', sort: true},
                    {
                        field: 'rksj',
                        title: '应征时间',
                        width: 120,
                        align: "center",
                        sort: true,
                        templet: function (d) {
                            if (!d.rksj) {
                                return '';
                            }
                            return layui.util.toDateString(d.rksj, 'yyyy-MM-dd');
                        }
                    },
                    {
                        field: 'rkje',
                        title: '应征额',
                        width: 180,
                        align: 'center',
                        totalRow: true,
                        templet: function (d) {
                            return setNumber2(d.rkje);
                        }
                    }
                ]
            ]
            , toolbar: '#toolbar'
        });
        //应征日期
        laydate.render({
            elem: '#yzrqTime'
            , type: 'date'
            , range: '~'
            , done: function (value) {
                if (value !== null && value !== undefined && value !== "") {
                    startTime = value.split("~")[0];
                    endTime = value.split("~")[1];
                } else {
                    startTime = null;
                    endTime = null;
                }

            }
        });
        //初始化检查科室查询条件
        CoreUtil.sendPost("/gzcb/getJcks", null, function (res) {
            let datas = res.data;
            let options = "<option value = ''>请选择检查科室</option>";
            for (let i = 0; i < datas.length; i++) {
                options += '<option value="' + datas[i].jcks + '">' + datas[i].jcks + '</option>';
            }
            $('#checkKeShi').append(options);
            // 更新select渲染
            form.render('select');
        });
        //初始化区域
        CoreUtil.sendPost("/attention/gy/getallarea", null, function (res) {
            let datas = res.data;
            let options = "<option value = ''>请选择所属区</option>";
            for (let i = 0; i < datas.length; i++) {
                options += '<option value="' + datas[i].swjgDm + '">' + datas[i].swjgmc + '</option>';
            }
            $('#area').append(options);
            // 更新select渲染
            form.render('select');
        });
        //欠税统计表 - 查询
        form.on('submit(search)', function () {
            search();
        })
        form.on('submit(reset)', function () {
            reset();
        })
        form.on('submit(export)', function () {
            layer.confirm('确定导出所有数据?', {icon: 3, title: '提示'}, function (index) {
                const mapArr = {
                    nsrsbh: $("#nsrsbh").val(),
                    nsrmc: $("#nsrmc").val(),
                    startTime: startTime,
                    endTime: endTime,
                    bz: $("#caseType").val(),
                    jcks: $("#checkKeShi").val(),
                    area: $("#area").val()
                };
                CoreUtil.sendPost("/gzcb/exportGzcbData", mapArr, function (res) {
                    if (res.code === 0) {
                        var data = res.data;
                        if (!CoreUtil.isEmpty(data)) {
                            //全部导出
                            table.exportFile(tableIns1.config.id, data, 'xls');
                            //导出时阻止页面刷新
                            $(".layui-form").submit(function (e) {
                                e.preventDefault();
                            })
                        } else {
                            layer.alert('未查询到需要导出的数据！', {icon: 2});
                        }
                    }
                });
                layer.close(index);
            });
        })
    });

    //执行查询
    function search() {
        console.log("startTime", startTime)
        //这里以搜索为例
        tableIns1.reload({
            where: { //设定异步数据接口的额外参数，任意设
                nsrsbh: $("#nsrsbh").val(),
                nsrmc: $("#nsrmc").val(),
                startTime: startTime,
                endTime: endTime,
                bz: $("#caseType").val(),
                jcks: $("#checkKeShi").val(),
                area: $("#area").val()
            }
            , page: {
                curr: 1 //重新从第 1 页开始
            }
        });
    }

    function reset() {
        document.getElementById('searchForm').reset(); // 原生重置表单
        $('#yzrqTime').val(''); // 清空输入框
        startTime = null; // 重置结束时间
        endTime = null;
        $("#caseType").val(''); //清空下拉选
        $("#checkKeShi").val(''); //清空下拉选
        $("#area").val(''); //清空下拉选
        form.render(); // 重新渲染 Layui 的动态组件
    }

    //设置数值保留小数点后两位
    function setNumber2(value) {
        value = parseFloat(value);  // 将值转换为浮动数字
        if (!isNaN(value)) {
            return value.toFixed(2);  // 如果是有效数字，保留两位小数
        }
        return value;
    }
</script>
</body>
</html>